package com.market.controller.wx;

import com.market.bean.MarketAddress;
import com.market.bean.MarketUser;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.vo.wx.WxOrderListVo;
import com.market.service.wx.WxAddressService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author Zqp
 * @since 2023/1/2 11:14
 */

@RestController
@RequestMapping("wx/address")
public class WxAddressController {

    @Autowired
    WxAddressService addressService;

    @RequestMapping("list")
    public BaseRespVo list() {
        CommonData<MarketAddress> data = addressService.list();
        return BaseRespVo.ok(data);
    }

    @RequestMapping("save")
    public BaseRespVo save(@RequestBody Map map) {
        Subject subject = SecurityUtils.getSubject();
        int code = addressService.save(map);
        if(code == 1){
            return BaseRespVo.addressSaveOk();
        }
        return BaseRespVo.systemError();
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        MarketAddress data = addressService.detail(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        int code = addressService.delete(map);
        if(code == 1){
            return BaseRespVo.ok();
        }
        return BaseRespVo.systemError();
    }

}
